<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'all.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript" src="js/js1.js"></script>
</head>
<%
	//接受num1,num2,operator
	String num1 = request.getParameter("num1");
	String num2 = request.getParameter("num2");
	String operator = request.getParameter("operator");
	double d_num1 = 0;
	double d_num2 = 0;
	double res = 0;
	//判断接收到的数据是否为null
	if (num1 != null && num2 != null && operator != null) {
		d_num1 = Double.parseDouble(num1);
		d_num2 = Double.parseDouble(num2);

		//运算

		if (operator.equals("+")) {
			res = d_num1 + d_num2;
		} else if (operator.equals("-")) {
			res = d_num1 - d_num2;
		} else if (operator.equals("*")) {
			res = d_num1 * d_num2;
		} else if (operator.equals("/")) {
			res = d_num1 / d_num2;
		}
		//out.println("res=" + res);
	}
%>
<body>
	<form action="/jsp2/all.jsp" method="post" onsubmit="return checkNUm()">
		请输入第一个数:<input type="text" id="num1" value="<%=num1 %>" name="num1" /><br />
		 请输入第二个数:<input type="text" id="num2" value="<%=num2 %>"  name="num2" /><br />
		  请选择运算符:<select name="operator">
			<option value="+">+</option>
			<option value="-">-</option>
			<option value="*">*</option>
			<option value="/">/</option>
		</select><br /> <input type="submit" value="计算" />
	</form>
	<hr />
	运算结果是<%=res%>
</body>
</html>
